package com.defect.service.securityService.securityServiceImpl;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.defect.bo.ResultBo;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.ObjectMapper;

@Service
public class FailureHandler implements AuthenticationFailureHandler{
	
	private ObjectMapper objectMaperr = new ObjectMapper();
	
	@Override
	public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
			AuthenticationException exception) throws IOException, ServletException {
		String json = objectMaperr.writeValueAsString(new ResultBo("500", "登录失败", exception, null));
		response.setContentType("application/json;charset=utf-8");
		response.getWriter().write(json);
		response.getWriter().flush();
		
	}

}
